 
function Preference() {
    var pref = {};
    var defaultVersion ='0';
    var my_media = null;
    var mediaTimer = null;
    var url_radio="http://vipmms9.yacast.net/cap_radio";
    var isPlayed=false;
    
    // return parameters
    return {
        playAudio : function() {
            // Create Media object from src
            if(!isPlayed){
            this.my_media = new Media(url_radio, this.onSuccess, this.onError);
            // Play audio
            this.my_media.play();
            this.isPlayed=true;
            // Update my_media position every second
//            if (this.mediaTimer == null) {
//                this.mediaTimer = setInterval(function() {
//                    // get my_media position
//                    this.my_media.getCurrentPosition(
//                        // success callback
//                        function(position) {
//                            if (position > -1) {
//                                setAudioPosition((position) + " sec");
//                            }
//                        },
//                        // error callback
//                        function(e) {
//                            console.log("Error getting pos=" + e);
//                            setAudioPosition("Error: " + e);
//                        }
//                    );
//                }, 1000);
//            }
            }
        },
   
        pauseAudio:function () {
            if (this.my_media) {
                this.my_media.pause();
                this.isPlayed=false;

            }
        },

        // Stop audio
        // 
        stopAudio :function () {
            if (this.my_media) {
                this.my_media.stop();
                this.isPlayed=false;

            }
            clearInterval(mediaTimer);
            mediaTimer = null;
        },

        // onSuccess Callback
        //
        onSuccess :function () {
            alert("success")
            console.log("playAudio():Audio Success");
        },

        // onError Callback 
        //
        onError:function (error) {
            alert('code: '    + error.code    + '\n' + 
                  'message: ' + error.message + '\n');
        },

        // Set audio position
        // 
        setAudioPosition:function (position) {
            document.getElementById('audio_position').innerHTML = position;
        },
        
        
        init : function(){
//           if(!localStorage.getItem("preferences")){
//               this.setLang(defaultLang);
//               this.updateLocalStorage();
//           }
            
        },
        
        updateLocalStorage: function(){
           localStorage.setItem("preferences",Ext.encode(pref));
           
           //checks whether the local storage has been read or not
           this.read=false;
        } ,
        
        readFromLocalStorage: function(){
            //checks whether the local storage has been read or not
            if(!this.read){
            pref=Ext.decode(localStorage.getItem("preferences"));
            this.read=true;
           
            }
             return pref;
        },
    
        setDataVersion :function(dataVersion){
                pref.dataVersion=dataVersion;
                
        },
        getDataVersion : function() {
        	dataVersion =this.readFromLocalStorage().dataVersion;
            return dataVersion;
        },
		sph: function(){
		        	return host+"attachments/photos/small/";
		        },
		mph: function(){
		        	return host+"attachments/photos/med/";
		        },
		bph: function(){
		        	return host+"attachments/photos/big/";
		        }
    };
};
p=new Preference();
p.init();